#include "nodepage.h"
#include "sndatainterface.h"


NodePage::NodePage(int pageIndex, Node *node, QWidget *parent) :
    QWidget(parent)
{
    tabPageIndex = pageIndex;
    nodeName = node->nodeName;
//    CurNode = node;

    QGridLayout *layout = new QGridLayout();
    ADC  = new QListWidget();

    layout->addWidget(new QLabel(QString("NodeIP: %1").arg(node->nodeIP)),0,0);
    layout->addWidget(new QLabel(QString("Node Name: %1").arg(node->nodeName)),0,1);
    layout->addWidget(new QLabel(QString("Lat: %1").arg(node->nodeLocLat)),0,2);
    layout->addWidget(new QLabel(QString("Lon: %1").arg(node->nodeLocLon)),0,3);
    layout->addWidget(new QLabel(QString("Northing: %1").arg(node->nodeLocN)),0,4);
    layout->addWidget(new QLabel(QString("Easting: %1").arg(node->nodeLocE)),0,5);
    layout->addWidget(ADC,1,0,1,3);

    //ADC->addItem(new QListWidgetItem(QString("ALL %1").arg(node->nodeName)));
    ADC->addItem(new QListWidgetItem("PIR L "));
    ADC->addItem(new QListWidgetItem("PIR C "));
    ADC->addItem(new QListWidgetItem("PIR R "));
    ADC->addItem(new QListWidgetItem("ACC X "));
    ADC->addItem(new QListWidgetItem("ACC Y "));
    ADC->addItem(new QListWidgetItem("ACC Z "));
    ADC->addItem(new QListWidgetItem("MAG X "));
    ADC->addItem(new QListWidgetItem("MAG Y "));
    ADC->addItem(new QListWidgetItem("COMP X"));
    ADC->addItem(new QListWidgetItem("COMP Y"));
    ADC->addItem(new QListWidgetItem("MIC   "));
    ADC->addItem(new QListWidgetItem("MIC E "));
    ADC->addItem(new QListWidgetItem("SYSM  "));
    ADC->addItem(new QListWidgetItem("SYSM E"));

    setLayout(layout);

    connect(ADC, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(reportChange(QModelIndex)));
}


void NodePage::reportChange(QModelIndex index)
{
    emit(changeTimeGraphItem(this->tabPageIndex, index.row()));
}


void NodePage::changePageItemColor(int itemIndex, QColor color)
{
    ADC->item(itemIndex)->setBackgroundColor(color);
    if(color == Qt::white)
        ADC->item(itemIndex)->setTextColor(Qt::black);
    else
        ADC->item(itemIndex)->setTextColor(Qt::white);
}
